<html>
<head>
<meta charset="UTF-8">
<title>KBEngine - KBEngine loginapp</title>
<link href="../../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align=left style="background:#708090"> <font size=15 color=#ffffff> KBEngine </font></td></tr>
</table> <hr>
<h1>KBEngine module</h1>
This <a href="KBEngine.html">KBEngine</a> module provides Python scripts 
control over the loginapp process to handle entity login registration.


<h2><a href="#" onClick="obj=document.getElementById( 'functions' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Member functions</a></h2>
<table id="functions" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#addTimer" class="function_list" >addTimer</a>( initialOffset, repeatOffset=0, callbackObj=None ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#delTimer" class="function_list" >delTimer</a>( id ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#urlopen" class="function_list" >urlopen</a>( url, callback, postData, headers ):</span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'callbacks' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Callback functions</a></h2>
<table id="callbacks" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#onLoginAppReady" class="function_list" >onLoginAppReady</a>( ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onLoginAppShutDown" class="function_list" >onLoginAppShutDown</a>( ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onRequestLogin" class="function_list" >onRequestLogin</a>( loginName, password, clientType, datas ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onLoginCallbackFromDB" class="function_list" >onLoginCallbackFromDB</a>( loginName, accountName, errorno, datas ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onRequestCreateAccount" class="function_list" >onRequestCreateAccount</a>( accountName, password, datas ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onCreateAccountCallbackFromDB" class="function_list" >onCreateAccountCallbackFromDB</a>( accountName, errorno, datas ):</span>
</td></tr>
</table>


<hr>
<h2>Member functions documentation</h2>

<a name="addTimer"></a><p class="function_definition">
<span class="function_definition">def addTimer( <i>initialOffset, repeatOffset=0, callbackObj=None</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Register a timer. The timer is triggered by the callback function 
callbackObj. The callback function will be executed the first time 
after "initialOffset" seconds, and then will be executed once every 
"repeatOffset" seconds. 
<br><br>
Example:

<pre><pre># Here is an example of using addTimer
        import <a href="../Modules/KBEngine.html">KBEngine</a>
&nbsp;
        # Add a timer, perform the first time after 5 seconds, and execute once every 1 second. The user parameter is 9
        KBEngine.addTimer( 5, 1, onTimer_Callbackfun )
&nbsp;
        # Add a timer and execute it after 1 second. The default user parameter is 0.
        KBEngine.addTimer( 1, onTimer_Callbackfun )
&nbsp;
    def onTimer_Callbackfun( id ):
        print "onTimer_Callbackfun called: id %i" % ( id )
        # If this is a repeated timer, it is no longer needed, call the following function to remove: 
        #     KBEngine.delTimer( id )</pre>
</pre>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>initialOffset</i></span></td><td><span class="function_parameter_description">
float, specifies the time interval in seconds for the timer to register from the first callback.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>repeatOffset</i></span></td><td><span class="function_parameter_description">
float, specifies the time interval (in seconds) between each execution after  
the first callback execution. You must remove the timer with the function 
<a href="#delTimer">delTimer</a>, otherwise it will continue to repeat. 
Values less than or equal to 0 will be ignored.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callbackObj</i></span></td><td><span class="function_parameter_description">
function, the specified callback function object
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>integer, the internal id of the timer. This id can be used to 
remove the timer using <a href="#delTimer">delTimer</a>
</td></tr>
</table>
</p>



<a name="delTimer"></a><p class="function_definition">
<span class="function_definition">def delTimer( <i>id</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
The function delTimer is used to remove a registered timer. The removed 
timer is no longer executed. Single-shot timers are automatically removed 
after the callback is executed, and it is not necessary to use delTimer 
to remove it. If the delTimer function uses an invalid id (for example, 
has been removed), it will generate an error
<br><br>
A use case for the KBEngine.addTimer reference timer.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>id</i></span></td><td><span class="function_parameter_description">
integer, timer id to remove
</span></td></tr>

</table>
</p>



<a name="urlopen"></a><p class="function_definition">
<span class="function_definition">def urlopen( <i>url, callback, postData, headers</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This script function is providing an external HTTP/HTTPS asynchronous request.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>url</i></span></td><td><span class="function_parameter_description">
A valid HTTP/HTTPS URL.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td>
<td><p class="function_parameter_description">
Optional parameter with a callback object (for example, a function) that requests execution results. This callback takes five parameters: the HTTP request return code (eg: 200), 
the returned content, the returned HTTP protocol header, whether it succeeded, and the requested URL.
<br>
Example:<br>
def 
onHttpCallback(httpcode, data, headers, success, url):<br>
&nbsp;&nbsp;&nbsp;&nbsp;print(httpcode, data, headers, success, url)  <br>
<br>
As the above example shows:
<br><p class="function_parameter_description"></p>httpcode:The parameter corresponds to the &quot;HTTP request return code&quot;, is an integer.
<p class="function_parameter_description"></p>data:The parameter is &ldquo; returned content & rdquo;, it is a string.
</p>
<p class="function_parameter_description">headers:The parameter is the HTTP protocol header returned by the server, such as:{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
<p class="function_parameter_description">success:Whether the execution is successful or not, when the request execution has an error, it is False, and the error information can be further judged by httpcode.
</p>
<p class="function_parameter_description"></p>url:Is the URL used by the request.
</p>
</td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>postData</i></span></td><td><span class="function_parameter_description">
Optional parameter, the default is GET mode request server. If you need POST mode, please provide the content that needs POST. The engine will automatically request the server using POST, is an bytes.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>headers</i></span></td><td><span class="function_parameter_description">
Optional parameter, HTTP header used when requesting, such as：{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
</span></td></tr>

</table>
</p>




<hr>
<h2>Callback functions documentation</h2>

<a name="onLoginAppReady"></a><p class="function_definition">
<span class="function_definition">def onLoginAppReady( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when the current process is ready.
<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).
</div>



<a name="onLoginAppShutDown"></a><p class="function_definition">
<span class="function_definition">def onLoginAppShutDown( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Process shutdown calls this function back. 
<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).
</div>



<a name="onRequestLogin"></a><p class="function_definition">
<span class="function_definition">def onRequestLogin( <i>loginName, password, clientType, datas</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Called back when the client requests the server login account.
<br><br>
Here you can do some administrative control on user login. For example:<br> 
Use this interface to truncate the user's login here, record the request 
and queue it, and return an error code to tell the client the queue 
status.
<br><br>
Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).<br>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>loginName</i></span></td><td><span class="function_parameter_description">
string, the name of the account submitted when logging in.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>password</i></span></td><td><span class="function_parameter_description">
string, MD5 password.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>clientType</i></span></td><td><span class="function_parameter_description">
integer, client type, given when the client logs in.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>datas</i></span></td><td><span class="function_parameter_description">
bytes, the data attached to the client request, can forward data to a third-party platform.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Tuple, the return value is (error code, real account name, password, client type, data data submitted by the client), if there is no need to extend the modification, the return value is usually to destroy the incoming value (KBEngine.SERVER_SUCCESS , loginName, password, clientType, datas).
</td></tr>
</table>
</p>



<a name="onLoginAppReady"></a><p class="function_definition">
<span class="function_definition">def onLoginAppReady( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when the current process is ready. 
<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).
</div>



<a name="onLoginAppShutDown"></a><p class="function_definition">
<span class="function_definition">def onLoginAppShutDown( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Process shutdown calls this function back. 
<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).
</div>



<a name="onLoginCallbackFromDB"></a><p class="function_definition">
<span class="function_definition">def onLoginCallbackFromDB( <i>loginName, accountName, errorno, datas</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
The callback returned by dbmgr after the client requests the server 
login account.<br><br>

<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).<br>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>loginName</i></span></td><td><span class="function_parameter_description">
string, the name of the account submitted when logging in.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>accountName</i></span></td><td><span class="function_parameter_description">
string, the real account name (obtained from the the query at dbmgr)
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>errorno</i></span></td><td><span class="function_parameter_description">
integer, error code, if it is not KBEngine.SERVER_SUCCESS, login failed.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>datas</i></span></td><td><span class="function_parameter_description">
bytes, which may be any data, such as data returned by a third-party platform or data returned by dbmgr and interfaces when processing the login.
</span></td></tr>

</table>
</p>



<a name="onRequestCreateAccount"></a><p class="function_definition">
<span class="function_definition">def onRequestCreateAccount( <i>accountName, password, data</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Callback when the client requests the server to create an account.<br><br>

<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).<br>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>accountName</i></span></td><td><span class="function_parameter_description">
string, the name of the account submitted by the client.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>password</i></span></td><td><span class="function_parameter_description">
string, MD5 password.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>datas</i></span></td><td><span class="function_parameter_description">
bytes, the data attached to the client request, can forward data to a third-party platform.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Tuple, the return value is (error code, real account name, password, data data submitted by the client), if there is no need to extend the modified value is usually returned to destroy the incoming value (KBEngine.SERVER_SUCCESS, loginName, password , datas).
</td></tr>
</table>
</p>




<a name="onCreateAccountCallbackFromDB"></a><p class="function_definition">
<span class="function_definition">def onCreateAccountCallbackFromDB( <i>accountName, errorno, datas</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
The callback returned by dbmgr after the client requests the server to create an account.<br><br>

<br>Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).<br>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">


<tr valign=top><td><span class="function_parameter_name"><i>accountName</i></span></td><td><span class="function_parameter_description">
string, the name of the account submitted by the client.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>errorno</i></span></td><td><span class="function_parameter_description">
integer, error code, if it is not KBEngine.SERVER_SUCCESS, login failed.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>datas</i></span></td><td><span class="function_parameter_description">
bytes, which may be any data, such as data returned by a third-party platform or data returned by dbmgr and interfaces when processing the login.
</span></td></tr>

</table>
</p>




<hr>
<p class="copyrightFooter">Copyright KBEngine</p>
</body>
</html>
